package com.sskj.fabi.http;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.fabi.bean.FBPrice;
import com.sskj.fabi.bean.FabiBuyBean;
import com.sskj.fabi.bean.FabiListBean;
import com.sskj.fabi.bean.OrderDetailBean;
import com.sskj.fabi.bean.PayWayBean;
import com.sskj.fabi.bean.PublishBean;
import com.sskj.fabi.bean.RecordTradeBean;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.SysConfigBean;

import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {

    @Override
    public PostRequest<HttpData<PageBean<FabiListBean>>> getFbList(int page, int size, boolean isBuy) {
        return OkGo.<HttpData<PageBean<FabiListBean>>>post(HttpConfig.BASE_URL + HttpConfig.FABI_LIST)
                .params("p", page)
                .params("size", size)
//                .params("pid", "BDD")  // 默认BDD
                .params("type", isBuy ? "2" : "1");  // 1 购买  2 出售
    }

    @Override
    public GetRequest<HttpData<List<PayWayBean>>> getPayList() {
        return OkGo.<HttpData<List<PayWayBean>>>get(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST);
    }

    @Override
    public GetRequest<HttpData<FBPrice>> getFbPrice() {
        return OkGo.<HttpData<FBPrice>>get(HttpConfig.BASE_URL + HttpConfig.FABU_PRICE);
    }

    @Override
    public GetRequest<HttpData<PageBean<RecordTradeBean>>> getRecordList(int p, int size) {
        return OkGo.<HttpData<PageBean<RecordTradeBean>>>get(HttpConfig.BASE_URL + HttpConfig.C2C_RECORD)
                .params("p", p)
                .params("size", size);
    }


    @Override
    public GetRequest<HttpData<PageBean<PublishBean>>> getFaBuRecord(String type, int p, int size) {
        return OkGo.<HttpData<PageBean<PublishBean>>>get(HttpConfig.BASE_URL + HttpConfig.FABU_RECORD)
                .params("p", p)
                .params("size", size)
                .params("type", type);
    }

    @Override
    public PostRequest<HttpData> markPay(String entrustNo) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_MARK_PAY)
                .params("order_no", entrustNo);
    }

    @Override
    public PostRequest<HttpData> allegeOrder(String orderNum, String refer, String shop_account, String ss_type, String ss_reason) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_ALLEGE)
                .params("order_num", orderNum)
                .params("refer", refer)
                .params("shop_account", shop_account)
                .params("ss_type", ss_type)
                .params("ss_reason", ss_reason);
    }

    @Override
    public PostRequest<HttpData> letGo(String tradeId, String tradePwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_LET_GO)
                .params("order_no", tradeId)
                .params("tpwd", tradePwd);
    }

    @Override
    public GetRequest<HttpData<OrderDetailBean>> getOrderDetail(String entrustNo) {
        return OkGo.<HttpData<OrderDetailBean>>get(HttpConfig.BASE_URL + HttpConfig.ORDER_LIST_BUY)
                .params("order_num", entrustNo);
    }

    @Override
    public PostRequest<HttpData> cancelFabiTradeOrder(String orderNum) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_CANCLE)
                .params("order_num", orderNum);
    }

    @Override
    public PostRequest<HttpData<PageBean<PublishBean>>> getFabiPublishOrderList(int page, int pageSize, String entrustNo) {
        return OkGo.<HttpData<PageBean<PublishBean>>>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_LIST)
                .params("entrustNo", entrustNo)
                .params("page", page)
                .params("pageSize", pageSize);
    }

    @Override
    public PostRequest<HttpData> cancelFabiPublishOrder(boolean isBuy, String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_CANCLE)
                .params("orderId", id)
                .params("tradeType", isBuy ? 1 : 2);
    }

    @Override
    public PostRequest<HttpData<FabiBuyBean>> coinOrder(String tpwd, String order_no, String total_num, String total_price, int isBuy) {
        return OkGo.<HttpData<FabiBuyBean>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_FABI_ORDER)
                .params("tpwd", tpwd)     // 支付密码   委托单号  数量  价钱  出售/求购  id  支付方式
                .params("order_no", order_no)  // 委托单号
                .params("total_num", total_num)
                .params("total_price", total_price)
                .params("type", isBuy);  // 买卖方向  1出售 2 购买
    }


    @Override
    public PostRequest<HttpData> createFabiOrder(String trans_num, String min_price, String max_price,
                                                 String type, int pay_wx, int pay_alipay, int pay_backcard, int paypal, String notes, String pay_pwd) {

        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PUBLISH)
                .params("type", type)  // 交易类型
                .params("trans_num", trans_num)
                .params("min_price", min_price)
                .params("max_price", max_price)
                .params("pay_wx", pay_wx)
                .params("pay_alipay", pay_alipay)
                .params("pay_backcard", pay_backcard)
                .params("paypal", paypal)
                .params("notes", notes)
                .params("pay_pwd", pay_pwd);  // 支付密码;
    }


    @Override
    public PostRequest<HttpData<List<SysConfigBean>>> getSysConfig(int type) {
        return OkGo.<HttpData<List<SysConfigBean>>>post(HttpConfig.BASE_URL + HttpConfig.SYS_CONFIG)
                .params("type", type);
    }

    @Override
    public PostRequest<HttpData> cancleOrder(String type, int id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_PUBLISH_ORDER_CANCLE)
                .params("id", id)
                .params("type", type);
    }


}